#define DEBUG
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn=1000000;

class Range {
public:
  int l, r;

  static bool cmp(Range &a, Range &b) {
    return a.l<b.l || (a.l==b.l && a.r<b.r);
  }
};

class SegmentTree {
public:
  int a[4*maxn+1];

  void set(int o, int l, int r, int t, int tv) {
    if (l==r) {
      a[o] = max(a[o], tv);
    } else {
      int mid=(l+r)/2;
      if (t<=mid) {
        set(o*2, l, mid, t, tv);
      } else {
        set(o*2+1, mid+1, r, t, tv);
      }
      a[o] = max(a[o*2], a[o*2+1]);
    }
  }

  int get(int o, int l, int r, int tl, int tr) {
    if (l==tl && r==tr) {
      return a[o];
    } else {
      int mid=(l+r)/2, ret=0;
      if (tl<=mid) {
        ret = max(ret, get(o*2, l, mid, max(tl, l), min(tr, mid)));
      }
      if (tr>mid) {
        ret = max(ret, get(o*2+1, mid+1, r, max(tl, mid+1), min(tr, r)));
      }
      return ret;
    }
  }
};

ll runAtoB(int an, Range a[], int &bn, Range b[]) {
	static SegmentTree sgt;
  ll ret=0;
  bn = 0;
  int maxr=0;
  for (int i=1; i<=an; i++) {
    if (a[i].r>maxr) {
			b[++bn] = a[i];
			maxr = a[i].r;
			sgt.set(1, 1, maxn, a[i].r, a[i].r-a[i].l);
		} else {
			ret = max(ret, (ll)sgt.get(1, 1, maxn, a[i].r, maxn)*(a[i].r-a[i].l));
		}
  }
	return ret;
}

ll calc(Range &a, Range &b) {
	return max((ll)(min(a.r, b.r)-max(a.l, b.l))*(max(a.r, b.r)-min(a.l, b.l)), 0LL);
}

void dp(int l, int r, int x, int y, Range a[], ll f[]) {
	if (l>r) {
		return;
	}
	int mid=(l+r)/2, t=x;
	for (int i=x; i<mid && i<=y; i++) {
		if (calc(a[i], a[mid])>f[mid]) {
			f[mid] = calc(a[i], a[mid]);
			t = i;
		}
	}
	dp(l, mid-1, x, t, a, f);
	dp(mid+1, r, t, y, a, f);
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static Range a[maxn+1], b[maxn+1];
  int an, bn;
  scanf("%d", &an);
  for (int i=1; i<=an; i++) {
    scanf("%d %d", &a[i].l, &a[i].r);
  }

  sort(a+1, a+an+1, Range::cmp);
  
  ll ans=runAtoB(an, a, bn, b);

	static ll f[maxn+1];
	dp(1, bn, 1, bn, b, f);
	for (int i=1; i<=bn; i++) {
		ans = max(ans, f[i]);
	}
	printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
